package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.home.SiteQuery;
import tcu.iot.gasmanage.service.HomeService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api
@RestController
@RequestMapping("/home")
@CrossOrigin
public class HomeController {

    @Resource
    private HomeService homeService;

    @ApiOperation(value = "/getStateData", notes = "获取饼状图数据")
    @GetMapping(value = "/getStateData")
    public Result getStateData() {
        return homeService.getStateData();
    }

    @ApiOperation(value = "getSecondSeriesData", notes = "获取设备状态信息数量图表接口")
    @GetMapping(value = "/getRegionData")
    public Result getSecondSeriesData() {
        return homeService.getProvinceData();
    }

    @ApiOperation(value = "HomeBarChartData", notes = "获取主页柱状图信息")
    @GetMapping(value = "/HomeBarChartData")
    public Result getHomeBarChartData(HttpServletRequest request) {
        SiteQuery site = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), SiteQuery.class);

        return homeService.getHomeBarChartData(site);
    }

    @ApiOperation(value = "getSiteOptions", notes = "获取首页柱状图中所需的站点信息")
    @GetMapping("/getSiteOptions")
    public Result getSiteOptions() {
        return homeService.getSiteOptions();
    }
}
